package com.pw.study.flink.source;

import com.pw.study.flink.entities.WaterSensor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

public class CollectionSource {
    public static void main(String[] args) {
        dealCollection();
    }

    private static void dealCollection() {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        List<WaterSensor> sensors = Arrays.asList(new WaterSensor("a", 20L, 40),
                new WaterSensor("b", 1L, 30),
                new WaterSensor("c", 6L, 5),
                new WaterSensor("d", 88L, 20));
        env.fromElements(sensors).print("元素:");
        env.fromCollection(sensors).print("集合:");
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
